import {ref} from "vue";
import http from "../http";

let musicLimit = 30;

/**
 * 获取轮播列表
 * @returns
 */
export function getBannerList() {
    return http.get("/banner?type=1");
}

/**
 * 获取热搜
 */
export function getSearchHot() {
    return http.get("/search/hot");
}

/**
 * 获取搜索建议
 */
export function getSearchSuggest(keyword) {
    return http.get("/search/suggest?keywords=" + keyword);
}

/**
 * 获得综合搜索
 * @param {*} keyword
 * @returns
 */
export function getSearchSynthetical(keyword) {
    return http.get("/search?keywords=" + keyword + "&type=1018")
}

/**
 * 获取音乐详情
 * @param ids
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getSongDetail(ids) {
    return http.get("/song/detail?ids=" + ids);
}

/**
 * 获取搜索的音乐
 * @param keyword
 * @param page
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getSearchSongs(keyword, page = 1) {
    page = (page - 1);
    return http.get("/cloudsearch?keywords=" + keyword + "&limit=" + musicLimit + "&offset=" + page * musicLimit);
}

/**
 * 获取搜索的歌单
 * @param keyword
 * @param page
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getSearchPlaylists(keyword, page = 1) {
    page = (page - 1);
    return http.get("/cloudsearch?keywords=" + keyword + "&limit=" + musicLimit + "&offset=" + page * musicLimit + "&type=1000");
}

/**
 * 获取评论
 * @param musicId
 * @param page
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getMusicComments(musicId, page) {
    page = (page - 1);
    return http.get("/comment/music?id=" + musicId + "&limit=" + musicLimit + "&offset=" + page * musicLimit)
}

/**
 * 获取音乐歌词
 * @param musicId
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getMusicLyric(musicId) {
    return http.get("/lyric?id=" + musicId);
}

/**
 * 获取歌单详情
 * @param id
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getPlayListDetails(id) {
    return http.get("/playlist/detail?id=" + id )
}

/**
 * 获取推荐歌单
 * @returns {Promise<AxiosResponse<any>>}
 */
export function getPersonalized(){
    return http.get("/personalized");
}

/**
 * 获取音乐是否可用
 * @param id
 * @returns {Promise<AxiosResponse<any>>}
 */
export function checkMusic(id){
    return http.get("/check/music?id="+id);
}